package com.es.jdk.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class PersistenceInvocationHandler implements InvocationHandler {
    //操纵的目标
    private Object target;
    //传递
    public PersistenceInvocationHandler(Object target){
        this.target = target;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //代理对象执行之前
        System.out.println("我开启事务了");
        Object result = method.invoke(target, args);
        //代理对象执行之后
        System.out.println("我执行完了，我可以提交事务了");
        // result
        System.out.println();
        return result;
    }
}
